/*
 * 作者		钱新才
 * 开发环境	Win7 Eclipse3.5 JDK1.6
 * 开发日期	2011-11-25
 */
package org.ufinity.hsms.common.impl;

import static org.ufinity.hsms.common.tool.logs.Logs.e;

import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;
import org.ufinity.hsms.common.utils.ZabbixApiClient;


public class GetDateImpl {

	private static final String TAG = "GetDateImpl";
	
	public static String paramString(HashMap<String, String> paramMap){
		String result = "{";
		int size = paramMap.size();
		for (Map.Entry<String, String> entry : paramMap.entrySet()) {
			result = result+"\""+entry.getKey()+"\":\""+ entry.getValue().toString()+"\"";
			if(size>1){
				size--;
				result = result + ",";
			}
		}
		result = result + "}";
		return result;
	}
	
	
	
	/**
	 * 登录
	 * 
	 * @Description
	 * @author 钱新才
	 * @version 1.0 2011-11-28
	 */
	public static JSONObject login(HashMap<String, String> paramMap) {
		try {
			return ZabbixApiClient.MakeRequest(2, "user.authenticate", false,paramString(paramMap));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}


	/**
	 * 获取主机组
	 * 
	 * @Description
	 * @author 钱新才
	 * @version 1.0 2011-11-28
	 */
	public static JSONObject getHostGroup() {
		return ZabbixApiClient.getHostGroup();
	}
	
	
	/**
	 * 获取主机
	 * 
	 * @Description
	 * @author 钱新才
	 * @version 1.0 2011-11-28
	 */
	public static JSONObject getHost(HashMap<String, String> map) {
		return ZabbixApiClient.getHost(map);
	}
	
	/**
	 * 获取分类项
	 * 
	 * @Description
	 * @author 钱新才
	 * @version 1.0 2011-11-28
	 */
	public static JSONObject getItems(String id) {
		return ZabbixApiClient.getAllItemsByHostId(id);
	}
	
	/**
	 * 根据主机id获取报警
	 * 
	 * @Description
	 * @author 钱新才
	 * @version 1.0 2011-11-28
	 */
	public static JSONObject getTrigger(String hostId) {
		return ZabbixApiClient.getTriggersByHostId(hostId);
	}

}
